package com.amex.uam.template;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Hashtable;
import java.util.Map;

public class TemplateManager {

	public static String TEMPLATE_Registration = "Registration.html";
	public static String TEMPLATE_Approve = "Registration.html";
	public static String TEMPLATE_Deny = "Registration.html";
	public static String TEMPLATE_OptBlue = "Registration.html"; 
	public static String TEMPLATE_GMAPS = "Registration.html";
	public static String TEMPLATE_Reminder = "Registration.html";
	
	private static Map<String, String> templateDict = new Hashtable<String, String>();
	
	public static String getTemplate(String templateName) {
		String temp = templateDict.get(templateName);
		if (temp == null) {
			temp = loadTemplate(templateName);
		}
		return temp;
	}
	
	private static String loadTemplate(String filename) {
		BufferedReader bin = null;
		try {
			bin = new BufferedReader(new InputStreamReader(
					TemplateManager.class.getResourceAsStream(filename)));
			String line;
			StringBuffer buff = new StringBuffer();
			while ((line = bin.readLine()) != null) {
				buff.append(line);
			}
			return buff.toString();
		} catch (Throwable t) {
			t.printStackTrace();
			return null;
		} finally {
			if (bin != null)
				try {
					bin.close();
				} catch (IOException e) {
				}
		}

	}
	
}
